<?php

namespace IDock\Insurance\AICS\Request;

use Exception;
use IDock\IDock\IDockEnums;
use IDock\Insurance\AICS\AICSEnums;
use IDock\Insurance\AICS\Request\AllAICSRequest;
use IDock\Insurance\AICS\Response\PremiumInquiryResponse;
use IDock\Visitor\NonCar\NonCarProductVisitor;
use IDock\Visitor\Premium\PremiumChargingPileVisitor;
use IDock\Visitor\Premium\PremiumCoverageVisitor;
use IDock\Visitor\Premium\PremiumExtInfoVisitor;
use IDock\Visitor\Premium\PremiumInquiryVisitor;
use IDock\Visitor\Premium\PremiumRelationVisitor;

class PremiumInquiryRequest extends AllAICSRequest
{
    public $code = 'NewPremiumXnyCalculationService';

    public $envelopeName = 'new:queryVehicleXnyQuotationService';

    protected $response = PremiumInquiryResponse::class;

    /**
     * @var PremiumInquiryVisitor $visitor
     */
    protected $visitor;

    protected $urlTip = '保费计算';

    /**
     * @return array
     * @throws Exception
     */
    public function generate(): array
    {
        $data = [
            'condition' => [
                'base' => $this->getBaseInfo(),
                'vhl' => $this->getVehicle(),
                'vhlowner' => $this->getCarOwner(),
                'applicant' => $this->getApplicant(),
                'insured' => $this->getInsured(),
                'prmCoef' => $this->getBiRate(),
                'coverageListJQ' => ['CvrgJQ' => $this->getJqList()],
                'vehicleAdjust' => $this->getVehicleAdjust(),
                'agent' => $this->getAgent(),
            ],
        ];
        //充电桩
        if (count($this->visitor->getChargingPileVisitorList())) {
            $data['chargingPostList'] = ['ChargingPost' => $this->chargeList()];
        }
        //车船税
        if($data['condition']['base']['CAppJqFlag'] == 'Y'){
            $data['condition']['tax'] = $this->getTax();
        }
        //商业险险种
        if($data['condition']['base']['AppSYFlag'] == 'Y'){
            $data['condition']['cvrgListSY'] = ['CvrgSY' => $this->getCoverageList()];
        }
        //非车信息
        if($data['condition']['base']['AppYWFlag'] == 'Y'){
            $data['condition']['cvrgYW'] = $this->getNocarList();
        }
        return $data;
    }

    /**
     * 获取基础信息
     * @return array
     */
    private function getBaseInfo()
    {
        $arr = [
            'CProdNoSY' => '',//产品号-商业险
            'CProdNoJQ' => '',//产品号-商业险 0326
            'CDptCde' => $this->visitor->getExtInfoVisitor()->argc['CDptCde'] ?? '',//机构代码 0580 成都代理点
            'TInsrncBgnTmSY' => $this->visitor->biStartData,//商业险起保时间
            'TInsrncEndTmSY' => $this->visitor->biEndData,//商业险截止时间
            'TInsrncBgnTmJQ' => $this->visitor->ciStartData,//交强险开始时间
            'TInsrncEndTmJQ' => $this->visitor->ciEndData,//交强险截止时间

            'TInsrncBgnTmYW' => '',//意外险保险起期
            'TInsrncEndTmYW' => '',//意外险保险止期
            'CRatioTyp' => '340001',//短期费率方式 340001 按日算 340002 按月算
            'NRatioCoef' => '1',//短期系数 保险期限1年，默认为 1.000000
            'NPrmRmbExch' => '1',//汇率 固定1
            'CAmtCur' => '01',//保额币种 01 人民币
            'CPrmCur' => '01',//保费币种 01 人民币
            'CChaType' => '191010',//专业代理业务
            'TIssueTm' => date('Y-m-d'),//签单日期
            'COprCde' => $this->visitor->getExtInfoVisitor()->argc['COprCde'] ?? '',//操作人代码
            'CBrkrCde' => $this->visitor->getExtInfoVisitor()->argc['agentCode'] ?? '',//代理人/经纪人
            'CSlsCde' => $this->visitor->getExtInfoVisitor()->argc['CSlsCde'] ?? '',//业务员代码
            'CAppJqFlag' => 'N',//若投保交强则该字段必传Y:是  N:否 默认产品：0326
            'CImmeffMrk' => ($this->visitor->biEffectFlag or $this->visitor->ciEffectFlag) ? '1' : '0',//1：即时生效 0：非即时生效
            'CUserType' => '0',//内外网用户标志 0 外网用户 1 内网用户
            'RenewalFlagJQ' => '',//续保标志(交强) 0 或 1
            'RenewalFlagSY' => '',//续保标志(商业) 0 或 1
            'OperatorCode' => $this->visitor->getExtInfoVisitor()->argc['operatorCode'] ?? '',//录入人
            'TaxFlag' => '',//车船税标志
            'OperateDate' => date('Y-m-d H:i:s'),//录单日期
            'InsuredName' => $this->visitor->getInsuredVisitor()->name,//被保险人姓名
            'UserType' => '0',//内外网用户标志 0 外网用户 1 内网用户
            'CustomerName' => $this->visitor->getApplicantVisitor()->name,//客户名称
            'AppName' => $this->visitor->getApplicantVisitor()->name,//投保人姓名
            'AppSYFlag' => 'N',//是否投保商业
            'AppYWFlag' => '',//是否投保意外
            'CBsnsTyp' => '19002',//业务来源 19002代理
            'AppContact' => $this->visitor->getInsuredVisitor()->name,

        ];
        //测试环境需打开
//        $arr['CBrkrCde'] = '045102190010';
        if($this->visitor->getPremiumRenewalVisitor()->biPolicyNo){
            $arr['RenewalFlagSY'] = 1;
        }
        if($this->visitor->getPremiumRenewalVisitor()->ciPolicyNo){
            $arr['RenewalFlagJQ'] = 1;
        }
        if(!empty($this->visitor->ciStartData)){
            $arr['CAppJqFlag'] = 'Y';
            $arr['TaxFlag'] = '1';
            $arr['CProdNoJQ'] = '0326';
            $arr['RenewalFlagJQ'] = '0';
//            $arr['TIssueTm'] = date('Y-m-d',strtotime($this->visitor->ciStartData));
        }
        if(!empty($this->visitor->biStartData)){
            $arr['AppSYFlag'] = 'Y';
            $arr['CProdNoSY'] = $this->visitor->getVehicleVisitor()->isNewEnergy ? '0369' : '0364';
            $arr['RenewalFlagSY'] = '0';
//            $arr['TIssueTm'] = date('Y-m-d',strtotime($this->visitor->biStartData));
        }
        //非车
        if(!empty($this->visitor->getNonCarInquiryVisitor()->getNonCarList())){
            $arr['TInsrncBgnTmYW'] = $this->visitor->ciStartData ?: $this->visitor->biStartData;
            $arr['TInsrncEndTmYW'] = $this->visitor->ciEndData ?: $this->visitor->biEndData;
            $arr['AppYWFlag'] = 'Y';
        }
        return $arr;
    }

    private function getTax()
    {
        $tax = $this->visitor->getCarTaxVisitor();
        $arr = [
            'TaxCurrentType' => AICSEnums::$taxTypeCode[$tax->taxTypeCode] ?? '',//收费方式
            'VehicleCategory' => $this->visitor->getVehicleVisitor()->vehicleStyleCode,//车辆类型
            'TaxPayerName' => $tax->taxpayerName,//
            'PayLastYear' => '0',//补交上年
            'TaxBeginDateCurrentYear' => $tax->taxStartDate,
            'IdType' => AICSEnums::$certificateTypeCode[$tax->taxpayerCertificateTypeCode] ?? '',//证照类型
            'TaxEndDateCurrentYear' => $tax->taxEndDate,
            'CalculatedType' => '349003001',//计算类型 349003001 年缴
            'VehecleTypeDetail' => AICSEnums::$carKindCode[$this->visitor->getVehicleVisitor()->carKindCode] ?? '',//车辆细分
            'VehicleQuality' => round($this->visitor->getVehicleVisitor()->wholeWeight/1000,2),
            'TaxpayerNO' => $tax->taxpayerCertificateNo,//纳税人识别号
            'TaxPaidDate' => $tax->taxDocumentDate,//缴税日期
            'TaxpayerAddress' => $this->visitor->getOwnerVisitor()->address,//纳税人地址
            'VehicleType' => '',//车辆分类
//            'Zip' => '',//邮政编码
            'TaxpayerType' => $this->visitor->getOwnerVisitor()->typeCode == 'R1' ? '338001' : '338003',//纳税人类别
            'Conruty' => '156',
            'Tel' => $this->visitor->getOwnerVisitor()->mobile,//纳税人电话
            'VehicleNo' => $this->visitor->getVehicleVisitor()->licenseNo,
            'Exhaust' => $this->visitor->getVehicleVisitor()->vehicleExhaust,
            'TaxDepartmentName' => $tax->taxDepartment,//税务机关名称
            'Department' => $tax->taxDepartmentCode,
        ];
        if(empty($arr['TaxCurrentType'])){
            throw new Exception("不支持该缴税类型");
        }
        if(empty($arr['IdType'])){
            throw new Exception("不支持该纳税人证件类型");
        }
        if(empty($arr['VehecleTypeDetail'])){
            throw new Exception("不支持该车辆类型");
        }
        $arr['VehicleType'] = $arr['VehecleTypeDetail'] == '3490010013' ? '349001001' : '349001002';
        if($arr['TaxCurrentType'] == '349002003'){
            $arr['VehicleType'] = '349001004';//免税车
            $arr['TaxReduceType'] = AICSEnums::$taxReductionCode[$tax->taxReductionCode] ?? '';//减免方案
            $arr['TaxReduceRsn'] = AICSEnums::$taxReductionReasonCode[$tax->taxReductionReasonCode] ?? '';
            $arr['ReduceNO'] = $tax->taxDocumentNumber;//减税凭证号
            if($arr['TaxReduceType'] == '3490020042'){
                $arr['TaxReduceProp'] = round($tax->taxFreeRate,2);
            }
            if(empty($arr['TaxReduceType'])){
                throw new Exception("不支持该减免税原因");
            }
        }elseif($arr['TaxCurrentType'] == '349002004'){
            $arr['VehicleType'] = '349001005';//减税车
            $arr['TaxReduceType'] = AICSEnums::$taxReductionCode[$tax->taxReductionCode] ?? '';//减免方案
            $arr['TaxReduceRsn'] = AICSEnums::$taxReductionReasonCode[$tax->taxReductionReasonCode] ?? '';
            $arr['ReduceNO'] = $tax->taxDocumentNumber;//减税凭证号
            if($arr['TaxReduceType'] == '3490020042'){
                $arr['TaxReduceProp'] = round($tax->taxFreeRate,2);
            }
            if(empty($arr['TaxReduceType'])){
                throw new Exception("不支持该减免税原因");
            }
        }elseif ($arr['TaxCurrentType'] == '349002002'){
            //完税
            $arr['PayNO'] = $tax->taxDocumentNumber;//完税证号
            $arr['TaxDocumentDate'] = $tax->taxDocumentDate;
            $arr['TaxPaidAreaCode'] = '05';//固定四川
        }
        return $arr;
    }

    /**
     * 车辆信息
     * @return array
     */
    private function getVehicle(): array
    {
        $vehicleVisitor = $this->visitor->getVehicleVisitor();
        $NNewPurchaseValue = 0;
        /**
         * @var PremiumCoverageVisitor $item
         */
        foreach ($this->visitor->getCoverageVisitorList() as $item)
        {
            if($item->coverageCode == 'C02001' or $item->coverageCode == 'C12001'){
                $NNewPurchaseValue = $item->amount;
                $rateD = $this->visitor->getExtInfoVisitor()->argc['negotiatePrice'] ?? 0;
                if(!empty($rateD)){
                    $NNewPurchaseValue = round($NNewPurchaseValue * $rateD,2);
                }
                if($NNewPurchaseValue > ($this->visitor->getExtInfoVisitor()->argc['actualValue'] ?? 0)){
                    throw new Exception("车损险最高金额不能超过折旧价:".($this->visitor->getExtInfoVisitor()->argc['actualValue'] ?? 0).'元');
                }
            }
        }

        $arr = [
            'CModelCde' => $vehicleVisitor->vehicleModelCode,//精友车型代码
            'CRegOwner' => $this->visitor->getOwnerVisitor()->name,//行驶证车主
            'CPlateNo' => $vehicleVisitor->licenseNo,
            'CEngNo' => $vehicleVisitor->engineNo,
            'CFrmNo' => $vehicleVisitor->vin,//车架号
            'CFstRegYm' => $vehicleVisitor->firstRegisterDate,//初次登记日期
            'CPlateTyp' => $vehicleVisitor->licenseTypeCode,//号牌种类
            'CUsageCde' => AICSEnums::$useNatureCode[$vehicleVisitor->useNatureCode] ?? '',//使用性质
            'CBizMrk' => $this->visitor->getOwnerVisitor()->typeCode == 'R1' ? '338001' : '338003',//所属性质
            'CVhlTyp' => $this->getVehicleSeatType($vehicleVisitor->vehicleSeat),//车辆种类
            'NSeatNum' => $vehicleVisitor->vehicleSeat,//核定载客数
            'NDisplacement' => $vehicleVisitor->vehicleExhaust,//排气量
            'CNewMrk' => $vehicleVisitor->isNewVehicle == 1 ? 0 : 1,//新旧车标志 0 新车,1 旧车
            'CGlassTyp' => '',//玻璃类型
            'CRegVhlTyp' => $vehicleVisitor->vehicleStyleCode,//行驶证车辆类型
            'NTonage' => $vehicleVisitor->vehicleTonnage,//吨位
            'CEcdemicMrk' => intval($vehicleVisitor->nonlocalCar),//是否外地车
            'CChgOwnerFlag' => intval($vehicleVisitor->isTransfer or $vehicleVisitor->isCiTransfer),//过户标志
            'TTransferDate' =>  $vehicleVisitor->transferDate ?: '',
            'CResvTxt7' => '',//续保单号（往年（续/转）保单号）
            'CQryCdeSY' => $this->visitor->getExtInfoVisitor()->argc['CQryCdeSY'] ?? '',//查询码-商业
            'CQryCdeJQ' => $this->visitor->getExtInfoVisitor()->argc['CQryCdeJQ'] ?? '',//查询码-交强
            'CBusType' => $this->visitor->getVehicleVisitor()->isNewVehicle ? 0 : 2,//业务类型 0：新保  todo 1：续保  2：转保
            'CMortgageMrk' => '0',//是否按揭车 不出贷款车
            'NActualValue' => $this->visitor->getExtInfoVisitor()->argc['actualValue'] ?? 0,//折旧价
            'NNewPurchaseValue' => $NNewPurchaseValue ?: $vehicleVisitor->actualValue,//协商价
            'NNewPriceValue' => $vehicleVisitor->vehiclePrice,//新车购置价
//            'NoticeType' => '',//公告型号
            'CInspectionCde' => AICSEnums::$carCheckCode[$this->visitor->getExtInfoVisitor()->carCheckCode] ?? '',
            'CInspectorNme' => '',
            'CInspectRec' => '',
            'CInspectTm' => '',
            'CAnswerSY' => '',//问题答案-商业 转保业务，第二次请求必传
            'CAnswerJQ' => '',//问题答案-交强 转保业务，第二次请求必传
//            'NMonDespRate' => $this->visitor->getExtInfoVisitor()->argc['NMonDespRate'] ?? '',//月折旧率
            'TResvTm3' => $vehicleVisitor->issueDate,//发证日期
            'CCheckCodeSY' => '',//转保校验码-商业
            'CCheckCodeJQ' => '',//转保校验码-交强
            'NDefDisplacement' => '',
            'CDisplacementLvl' => round($vehicleVisitor->power,1),//功率
            'WholeWeight' => round($vehicleVisitor->wholeWeight / 1000,2),//四川/广东交管平台整备质量
            'CModelNme' => $vehicleVisitor->vehicleModel,//车款名称
            'CScsyxz' => '',//四川平台使用性质
            'NGo' => '',//总牵引质量(KG)
            'SpecialDeclareReason' => $vehicleVisitor->isTransfer ? '33908' : '',//默认为空，过户传
            'FuelType' =>  AICSEnums::$energyType[$vehicleVisitor->energyTypeCode] ?? '',//能源类型
            'CPmFuelType' => AICSEnums::$energyType1[$vehicleVisitor->energyTypeCode] ?? '',//机动车能源类型
            'COtherEnergyTypeDesc' => '',//其他燃料（能源）种类描述
            'CPlateModelCde' => '',//
            'NResvNum1' => '',//
            'CGrpBuyContractNo' => '',//
            'NPoWeight' => '',//
        ];
        if($this->visitor->getVehicleVisitor()->isNewVehicle){
            $arr['CBusType'] = '0';//新保
        }
        if(empty($arr['CInspectionCde'])){
            throw new Exception("不支持该验车情况");
        }
        if(empty($arr['FuelType'])){
            throw new Exception("不支持该能源类型");
        }
        if($this->visitor->getExtInfoVisitor()->carCheckCode == 'CS3'){
            //已验车
            $arr['CInspectorNme'] = $this->visitor->getExtInfoVisitor()->carChecker;
            $arr['CInspectRec'] = '';//验车情况
            $arr['CInspectTm'] = $this->visitor->getExtInfoVisitor()->carCheckDate;
        }
        return $arr;
    }

    public function getVehicleSeatType($seat)
    {
        if($seat < 6){
            return '337001';
        }elseif ($seat < 10){
            return '337002';
        }elseif ($seat < 20){
            return '337003';
        }elseif ($seat < '36'){
            return '337004';
        }else{
            throw new Exception("不支持的车辆类型");
        }
    }
    private function getCarOwner()
    {
        $ownerVisitor = $this->visitor->getOwnerVisitor();
        $owner = [
            'COwnerNme' => $ownerVisitor->name,//
            'TBirthday' => $this->getBirthday($ownerVisitor->certificateNo),//车主出生日期
            'CSex' => $this->getGenderByIDcard($ownerVisitor->certificateNo),//
            'COwnerCls' => $ownerVisitor->typeCode == 'R1' ? '1' : '0',//0 法人 1个人
            'DrvOwnerCertiCode' => $ownerVisitor->certificateNo,
            'DrvOwnerCeritType' => AICSEnums::$certificateTypeCode[$ownerVisitor->certificateTypeCode] ?? '',//车主证件类型
            'CAreaCde' => '103132',//车主国家/地区 103132 中国
            'CMobile' => $ownerVisitor->mobile,
            'CProvince' => $ownerVisitor->provinceCode,
            'CCity' => $ownerVisitor->cityCode,
            'CCounty' => $ownerVisitor->areaCode,
            'ownerAddress' => $ownerVisitor->address,
            'CWorkdptKind' => '900',//单位性质
        ];
        if (empty($owner['DrvOwnerCeritType'])){
            throw new Exception("不支持该车主证件类型");
        }
        if($owner['COwnerCls'] == '0'){
            $owner['CWorkdptKind'] = '300';//单位性质 默认企业300
        }
        return $owner;
    }

    /**
     * 投保人信息
     * @return array
     */
    private function getApplicant(): array
    {
        $apply = $this->visitor->getApplicantVisitor();
        $applicationList = [
            'CAppNme' => $apply->name,
            'CClntAddr' => $apply->address,
            'CRelCde' => $apply->certificateNo == $this->visitor->getInsuredVisitor()->certificateNo ? '601005' : '601008',
            'CClntMrk' => $apply->typeCode  == 'R1' ? '1' : '0',//投保人客户分类
            'CCertfCls' => AICSEnums::$certificateTypeCode[$apply->certificateTypeCode],//投保人证件类型
            'CCertfCde' => $apply->certificateNo,//投保人证件号
            'TBirthday' => $this->getBirthday($apply->certificateNo),//投保人出生日期
            'CSex' => $this->getGenderByIDcard($apply->certificateNo),
            'CMobile' => $apply->mobile,//手机号
            'CEmail' => $apply->email,
            'CCntrNme' => $apply->linkManName ?: $apply->name,
            'TCertfClsValiDate' => $apply->certificateEndDate,
            'CResvTxt5' => '002',//职业 默认服务人员
            'CProvince' => $apply->provinceCode,
            'CCity' => $apply->cityCode,
            'CCounty' => $apply->areaCode,
            'CAreaCde' => '103132',//国家地区
            'TEffectedDate' => $apply->certificateStartDate,//有效起期
            'CZipCde' => '',
            'NResvNum3' => '500',//注册资本金 单位 万元
            'CTrdCde' => '2017O82',//行业 其他
            'CWorkDpt' => '900',//行业 其他
        ];
        if($apply->certificateEndDate == '2099-12-31'){
            $applicationList['TCertfClsValiDate'] = '9999-12-31';
        }

        //默认长期
        if (!($applicationList['TCertfClsValiDate'] ?? '')) {
            $applicationList['TCertfClsValiDate'] = '9999-12-31';
        }

        if (empty($applicationList['CCertfCls'])){
            throw new Exception("不支持该投保人证件类型");
        }
        if($applicationList['CClntMrk'] == '0'){
            $applicationList['CWorkDpt'] = '300';//单位性质 默认企业
            $applicationList['CTrdCde'] = '2017O82';// 行业 默认其他
        }
        return $applicationList;
    }

    /**
     * 被保人
     * @return array
     * @throws Exception
     */
    private function getInsured()
    {
        $insured = $this->visitor->getInsuredVisitor();
        $arr = [
            'CInsuredNme' => $insured->name,
            'CClntAddr' => $insured->address,
            'CClntMrk' =>  $insured->typeCode  == 'R1' ? '1' : '0',//被保人客户分类
            'CCertfCls' => AICSEnums::$certificateTypeCode[$insured->certificateTypeCode] ?? '',//被保人证件类型
            'CCertfCde' => $insured->certificateNo,
            'TBirthday' => $this->getBirthday($insured->certificateNo),
            'CSex' => $this->getGenderByIDcard($insured->certificateNo),
            'CMobile' => $insured->mobile,
            'CEmail' => $insured->email,
            'TCertfClsValiDate' => $insured->certificateEndDate,
            'CRelCdes' => $insured->certificateNo == $this->visitor->getApplicantVisitor()->certificateNo ? '601005' : '601008',//与投保人关系
            'CAreaCde' => '103132',//国家/地区 中国
            'CProvince' => $insured->provinceCode,
            'CCity' => $insured->cityCode,
            'CCounty' => $insured->areaCode,
            'TEffectedDate' => $insured->certificateStartDate,
            'CCntrNme' => $insured->linkManName,
            'CZipCde' => '',
            'CWorkDpt' => '900',//单位性质 默认企业
            'CResvTxt5' => '',//职业
            'NResvNum3' => '500',//注册资本金
        ];
        if($insured->certificateEndDate == '2099-12-31'){
            $arr['TCertfClsValiDate'] = '9999-12-31';
        }

        //默认长期
//        if (!($arr['TCertfClsValiDate'] ?? '')) {
//            $arr['TCertfClsValiDate'] = '9999-12-31';
//        }
        if (empty($arr['CCertfCls'])){
            throw new Exception("不支持该被保人证件类型");
        }
        if($arr['CClntMrk'] == '0'){
            $arr['CWorkDpt'] = '300';//单位性质 默认企业
            $arr['CTrdCde'] = '2017O82';//行业 默认其他
        }
        return $arr;
    }

    public function getCoverageList()
    {
        $coverageList = $this->visitor->getCoverageVisitorList();
        $list = [];
        /**
         * @var PremiumCoverageVisitor $value
         */
        foreach ($coverageList as $value) {
            if($value->coverageCode == 'C01001'){
                continue;//跳过交强险
            }
            $item['CCvrgNo'] = AICSEnums::$coverageCode[$value->coverageCode] ?? '';
            $item['NPerAmt'] = $value->amount;
            if(empty($item['CCvrgNo'])){
                throw new Exception("不支持".IDockEnums::$coverageCode[$value->coverageCode]."险种");
            }
            if(in_array($item['CCvrgNo'],['030151','030228','030102','030229'])){
                $item['NLiabDaysLmt'] = $value->quantity;
            }
            if(in_array($item['CCvrgNo'],['030235','030236','030237','030238','030209','030210','030211','030212'])){
                $item['NLiabDaysLmt'] = $value->serviceTimes;
            }
            if(in_array($item['CCvrgNo'],['030229','030102'])){
                //乘客险单个金额
                $item['NPerAmt'] = $value->unitAmount;
            }
            $list[] = $item;
        }
        return $list;
    }

    private function getVehicleAdjust()
    {
        return [
            'SecondaryOrganization' => '09',
            'CInsuranceGroup' => '',
            'DrunkDrivingFloatingRate' => '0',
            'DrinkDrivingDealTime' => '0',
            'DrinkDrivingNonDealTime' => '0',
            'DrunkDrivingDealTime' => '0',
            'DrunkDrivingNonDealTime' => '0',
            'DrinkDrivingTime' => '0',
            'DrunkDrivingTime' => '0',
            'TypeMismatchLastYear' => '0',
            'DrunkDrivingLastYear' => '0',
            'OverCommitmentLastYear' => '0',
        ];
    }

    private function getBiRate()
    {
        $rate = [
            'NAutonomyAdjust' => '1',
            'NResvNum4' => $this->visitor->getExtInfoVisitor()->expectedDiscount,
            'CResvTxt1' => 0,
        ];
        if (!empty($rate['NResvNum4'])) {
            $rate['CResvTxt1'] = 1;
        }
        return $rate;
    }

    private function getJqList()
    {
        return [[
            'CoverageSeq' => 1,
            'CoverageCode' => '030050',
            'CoverageAmount' => '200000',
        ]];
    }

    private function getAgent()
    {
        return [
            'AgentCode' => $this->visitor->getExtInfoVisitor()->argc['agentCode'] ?? '',
            'ConferCode' => $this->visitor->getExtInfoVisitor()->argc['ConferCode'] ?? '',
            'AgentType' => $this->visitor->getExtInfoVisitor()->argc['AgentType'] ?? '',
            'AgentNme' => $this->visitor->getExtInfoVisitor()->argc['agentNme'] ?? '',
            'CustNature' => '192099',//客户性质
            'SubCoNo' => $this->visitor->getExtInfoVisitor()->argc['ConferCode'] ?? '',
            'QlftNo' => $this->visitor->getExtInfoVisitor()->argc['QlftNo'] ?? '',
            'AgentProfId' => $this->visitor->getExtInfoVisitor()->argc['QlftNo'] ?? '',
            'salesmanNo' => $this->visitor->getExtInfoVisitor()->argc['CSlsCde'] ?? '',
            'AgentSaleNme' => '10501098B',
            'AgentStockMrk' => '189009',//代理
        ];
    }

    private function chargeList()
    {
        $list = [];
        $chargeList = $this->visitor->getChargingPileVisitorList();
        /** @var PremiumChargingPileVisitor $val */
        foreach ($chargeList as $key => $val) {
            $list[] = [
                'CType' => $val->chargingPileType,
                'CCode' => $val->chargingPileCode,
                'CKind' => $val->chargingPileKind,
                'CYearLimit' => $val->chargingPileYearLimit,
                'CAddressType' => $val->chargingPileAddressType,
                'CAddress' => $val->chargingPileAddress,
                'CLossSumLimit' => '',
                'CLiabilitySumLimit' => '',
                'CInsrncBgnTm' => '',
                'CInsrncEndTm' => '',
            ];
        }
        return $list;
    }

    private function getNocarList()
    {
        /**
         * @var NonCarProductVisitor $row
         */
        $row = $this->visitor->getNonCarInquiryVisitor()->getNonCarList()[0] ?? [];
        $coverage = [];
        if($row){
            $coverage = [
                'CInsuranceCode' => $row->planCode,
                'NInsuranceQuantity' => $row->insuredNum,
            ];
        }
        return $coverage;
    }

    /**
     * 通过身份证获取性别
     * @param $idcard
     * @return int
     * @throws Exception
     */
    private function getGenderByIDcard($idCard)
    {
        if (strlen($idCard) != 18) {
            throw new Exception("身份证位数不合法");
        }
        $gender = intval(substr($idCard, 16, 1)) % 2;
        return $gender ? '106001' : '106002';
    }

    private function getBirthday($idCard)
    {
        if (strlen($idCard) != 18) {
            throw new Exception("身份证位数不合法");
        }
        return substr($idCard, 6, 4) . '-' . substr($idCard, 10, 2) . '-' . substr($idCard, 12, 2);
    }
}
